package com.zdb.demo.design.pattern.structural.composite;

import java.util.ArrayList;
import java.util.List;

public class CourseCatalog extends CatalogComponent {

    private List<CatalogComponent> items = new ArrayList<>();
    private String name;

    public CourseCatalog(String name) {
        this.name = name;
    }

    @Override
    public void add(CatalogComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public void remove(CatalogComponent catalogComponent) {
        items.remove(catalogComponent);
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void print() {
        printByLevel(0);

    }

    @Override
    protected void printByLevel(int level) {
        printN("+", level);
        System.out.println("目录：" + name);
        for(CatalogComponent catalogComponent : items) {
            catalogComponent.printByLevel(level + 2);
        }
    }
}
